import 'package:flutter/material.dart';
import 'package:flutter_app_demo/pages/news_detail_page.dart';

class NewsListItem extends StatelessWidget {
  //     {
  //       "author": "Alias_Travis",
  //       "id": 146738,
  //       "title": "Red Panda Dev C++ —— C/C++ 集成开发环境",
  //       "type": 1,
  //       "authorid": 4937141,
  //       "pubDate": "2021-06-20 08:03:48",
  //       "object": 51692,
  //       "commentCount": 0
  //     },
  final Map<String, dynamic> data;

  NewsListItem({this.data});

  @override
  Widget build(BuildContext context) {
    return InkWell(
      onTap: () {
        //跳转到详情页
        Navigator.of(context).push(MaterialPageRoute(builder: (context1) {
          return NewsDetailPage(id: data["id"]);
        }));
      },
      child: Container(
        margin: const EdgeInsets.only(left: 20),
        decoration: BoxDecoration(
            border: Border(
          bottom: BorderSide(color: Color(0xffaaaaaa), width: 1.0),
        )),
        child: Padding(
          padding: const EdgeInsets.only(top: 10, bottom: 10, right: 20),
          child: Column(
            children: [
              Text(
                "${data["title"]}",
                style: TextStyle(
                  fontSize: 20,
                  fontWeight: FontWeight.bold,
                ),
                maxLines: 2,
                overflow: TextOverflow.ellipsis,
              ),
              SizedBox(
                width: 50.0,
              ),
              Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  Text(
                    "@ ${data["author"]} ${data["pubDate"].toString().split(" ")[0]}",
                    style: TextStyle(
                      fontSize: 14,
                      color: Color(0xaaaaaaaa),
                    ),
                  ),
                  Row(
                    children: [
                      Icon(
                        Icons.message,
                        color: Color(0xaaaaaaaa),
                      ),
                      Text(
                        data["commentCount"].toString(),
                        style: TextStyle(
                          fontSize: 14,
                          color: Color(0xaaaaaaaa),
                        ),
                      ),
                    ],
                  )
                ],
              )
            ],
          ),
        ),
      ),
    );
  }
}
